/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.GuiManager;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JMenuItem;

/**
 *
 * @author Jojo
 */
public class ObjectCardMotor extends ObjectCard{
    String motorPort = "A";
    
    ObjectCardMotor(String pName, int pSensorTyp){
        super(pName, pSensorTyp);
        this.setPreferredSize(new Dimension(180,50));
        this.setSize(new Dimension(180,50));
        this.setMaximumSize(new Dimension(180,50));
        this.setMinimumSize(new Dimension(180,50));
        this.addContextMenu();
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g.create();
        Dimension d = this.getSize();
        g2d.drawLine(0,20,d.width-2,20);
        g2d.drawString("motorPort = "+motorPort,  10,35);
    }
    
    void cardClicked(){
            String outputText = "Servomotor "+ objectName+" = new Servomotor(\""+this.motorPort+"\");"+"\n";
            GuiManager.getActivePane().insert(outputText, GuiManager.getActivePane().getCaretPosition());
        }
    
    void addContextMenu(){
        
                
                JMenuItem jmiChangeMotorPort = new JMenuItem();
        jmiChangeMotorPort.setText("ändere Motorport");

        
        
        jmiChangeMotorPort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                motorPort = getUserChange("Motorport festlegen (A, B oder C?)");
                repaint();
                validate();
            }
        });
        
        this.jPopupMenu1.add(jmiChangeMotorPort);
    }
    
}
